﻿using System;
using System.Windows.Forms;
using ImageResizer.Properties;

namespace ImageResizer.Profiles
{
    /// <summary>
    /// Formulaire permettant de saisir un nouveau profil de redimensionnement
    /// </summary>
    public partial class NewProfileForm : Form
    {
        #region CTOR
        /// <summary>
        /// Crée un nouveau formulaire de saisie de profile
        /// </summary>
        public NewProfileForm()
        {
            InitializeComponent();
        }
        #endregion

        #region Private properties
        /// <summary>
        /// Obtient le nom du profil
        /// </summary>
        private string ProfileName
        {
            get
            {
                return textBoxName.Text;
            }
        }

        /// <summary>
        /// Obtient la largeur du profil
        /// </summary>
        private int ProfileWidth
        {
            get
            {
                return Convert.ToInt32(numericUpDownWidth.Value);
            }
        }

        /// <summary>
        /// Obtient la hauteur du profil
        /// </summary>
        private int ProfileHeight
        {
            get
            {
                return Convert.ToInt32(numericUpDownHeight.Value);
            }
        }

        /// <summary>
        /// Indique s'il s'agit d'un profile pour redimensionnement
        /// </summary>
        private bool ProfileForThumbnails
        {
            get
            {
                return checkBoxThumbnails.Checked;
            }
        }
        #endregion

        #region Public properties
        /// <summary>
        /// Obtient le profil saisi
        /// </summary>
        internal Profile Profile
        {
            get
            {
                return new ResizeProfile(ProfileName, ProfileWidth.ToString(), ProfileHeight.ToString(), ProfileForThumbnails);
            }
        } 
        #endregion

        #region Private methods
        /// <summary>
        /// Gèe le bouton Validation
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ButtonValidateClick(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(textBoxName.Text))
            {
                MessageBox.Show(Resources.ErrorNameIsEmpty);
            }
            else
            {
                DialogResult = DialogResult.OK;
                Close();
            }
        }

        /// <summary>
        /// Gère le bouton annuler
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ButtonCancelClick(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
            Close();
        } 
        #endregion
    }
}
